home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / PublicDomain / Anwendungen / AmigaEYE_V39.7 / ScreenNotifly.lha / ScreenNotify / src / functions.c < prev    next >
C/C++ Source or Header  |  1995-03-26  |  4KB  |  139 lines

  1. /*
  2.  * functions.c V1.0
  3.  *
  4.  * Add & Remove SceenNotify clients
  5.  *
  6.  * (c) 1995 Stefan Becker
  7.  */
  8.  
  9. #include "screennotify.h"
  10.  
  11. /* Add a client to client list */
  12. static struct Node *AddClient(struct ClientListData *cld, ULONG size,
  13.                               struct MsgPort *port, BYTE pri)
  14. {
  15.  struct Node *n;
  16.  
  17.  DEBUGLOG(kprintf("AddClient: CLD 0x%08lx, Size %ld, Port 0x%08lx, Pri %ld\n",
  18.                   cld, size, port, pri);)
  19.  
  20.  /* Allocate memory for node */
  21.  if (n = AllocMem(size, MEMF_PUBLIC)) {
  22.  
  23.   DEBUGLOG(kprintf("AddClient: CLD 0x%08lx, Node 0x%08lx\n", cld, n);)
  24.  
  25.   /* Initialize node */
  26.   n->ln_Name = (char *) port;
  27.   n->ln_Pri  = pri;
  28.  
  29.   /* Obtain semaphore for client list data */
  30.   ObtainSemaphore(&cld->cld_Semaphore);
  31.  
  32.   DEBUGLOG(kprintf("AddClient: CLD 0x%08lx, Semaphore locked.\n", cld);)
  33.  
  34.   /* Insert node into client list */
  35.   Enqueue(&cld->cld_List, n);
  36.  
  37.   /* Release semaphore */
  38.   ReleaseSemaphore(&cld->cld_Semaphore);
  39.  
  40.   DEBUGLOG(kprintf("AddClient: CLD 0x%08lx, Semaphore released.\n", cld);)
  41.  }
  42.  
  43.  /* Return pointer to node as handle */
  44.  return(n);
  45. }
  46.  
  47. /* Remove a client from client list */
  48. static BOOL RemoveClient(struct SignalSemaphore *ss, struct Node *n, ULONG size)
  49. {
  50.  BOOL rc = FALSE;
  51.  
  52.  DEBUGLOG(kprintf("RemoveClient: SS 0x%08lx, Node 0x%08lx, Size %ld\n", ss, n, size);)
  53.  
  54.  /* Try to obtain semaphore for client list data */
  55.  if (AttemptSemaphore(ss)) {
  56.  
  57.   DEBUGLOG(kprintf("RemoveClient: SS 0x%08lx, Semaphore locked.\n", ss);)
  58.  
  59.   /* List locked, remove node from list */
  60.   Remove(n);
  61.  
  62.   /* Release semaphore */
  63.   ReleaseSemaphore(ss);
  64.  
  65.   DEBUGLOG(kprintf("RemoveClient: SS 0x%08lx, Semaphore released.\n", ss);)
  66.  
  67.   /* Free node */
  68.   FreeMem(n, size);
  69.  
  70.   /* All OK. */
  71.   rc = TRUE;
  72.  
  73.  } else {
  74.   struct Message *m;
  75.  
  76.   DEBUGLOG(kprintf("RemoveClient: SS 0x%08lx, Semaphore NOT locked!\n", ss);)
  77.  
  78.   /* List is busy, check port if a message arrived and reply it! */
  79.   if (m = GetMsg((struct MsgPort *) n->ln_Name)) ReplyMsg(m);
  80.  }
  81.  
  82.  DEBUGLOG(kprintf("RemoveClient: SS 0x%08lx, %s.\n", ss, rc ? "OK" : "Failed");)
  83.  
  84.  return(rc);
  85. }
  86.  
  87. /* Add a CloseScreen client */
  88. __geta4 APTR _AddCloseScreenClient(__A0 struct Screen *s, __A1 struct MsgPort *port,
  89.                                    __D0 BYTE pri)
  90. {
  91.  struct CloseScreenClientNode *cscn;
  92.  
  93.  /* Allocate memory for node */
  94.  if (cscn = (struct CloseScreenClientNode *)
  95.              AddClient(&ScreenNotifyBase->snb_CloseScreenClients,
  96.                        sizeof(struct CloseScreenClientNode), port, pri))
  97.  
  98.   /* Initialize node */
  99.   cscn->cscn_Screen = s;
  100.  
  101.  /* Return pointer to node as handle */
  102.  return(cscn);
  103. }
  104.  
  105. /* Remove a CloseScreen client */
  106. __geta4 BOOL _RemCloseScreenClient(__A0 struct Node *n)
  107. {
  108.  return(RemoveClient(&ScreenNotifyBase->snb_CloseScreenClients.cld_Semaphore,
  109.                      n, sizeof(struct CloseScreenClientNode)));
  110. }
  111.  
  112. /* Add a PubScreenStatus client */
  113. __geta4 APTR _AddPubScreenClient(__A0 struct MsgPort *port, __D0 BYTE pri)
  114. {
  115.  return(AddClient(&ScreenNotifyBase->snb_PubScreenClients, sizeof(struct Node), port,
  116.                   pri));
  117. }
  118.  
  119. /* Remove a PubScreenStatus client */
  120. __geta4 BOOL _RemPubScreenClient(__A0 struct Node *n)
  121. {
  122.  return(RemoveClient(&ScreenNotifyBase->snb_PubScreenClients.cld_Semaphore,
  123.                      n, sizeof(struct Node)));
  124. }
  125.  
  126. /* Add a Workbench client */
  127. __geta4 APTR _AddWorkbenchClient(__A0 struct MsgPort *port, __D0 BYTE pri)
  128. {
  129.  return(AddClient(&ScreenNotifyBase->snb_WorkbenchClients, sizeof(struct Node), port,
  130.                   pri));
  131. }
  132.  
  133. /* Remove a Workbench client */
  134. __geta4 BOOL _RemWorkbenchClient(__A0 struct Node *n)
  135. {
  136.  return(RemoveClient(&ScreenNotifyBase->snb_WorkbenchClients.cld_Semaphore,
  137.                      n, sizeof(struct Node)));
  138. }
  139.